<?php 
if(!isset($_SESSION))
session_start();
class Excution extends CI_Controller  {

        /**
        * Index Page for this controller.
        *
        * Maps to the following URL
        * 		http://example.com/index.php/welcome
        *	- or -  
        * 		http://example.com/index.php/welcome/index
        *	- or -
        * Since this controller is set as the default controller in 
        * config/routes.php, it's displayed at http://example.com/
        *
        * So any other public methods not prefixed with an underscore will
        * map to /index.php/welcome/<method_name>
        * @see http://codeigniter.com/user_guide/general/urls.html
        */
       private $_configs = null;
       function __construct()
        {
            parent::__construct();
            $this->load->helper('url');
            $this->load->library('smarty3','','smarty');
            $_SESSION["DRegion"]=isset($_SESSION["DRegion"])?$_SESSION["DRegion"]:"";
            $_SESSION["DRegionName"]=isset($_SESSION["DRegionName"])?$_SESSION["DRegionName"]:"Toàn Quốc";
        }
        public function index()
	{
            //print_r($_SESSION["aFoots"]);
	}
        function sendIMYahoo(){
            $yahooid="cauvong252";
            $status = @file_get_contents("http://opi.yahoo.com/online?u=$yahooid&m=a&t=1");
            $img="http://dealgiadung.com/deal_css/images/y-a.png";
            
            if($status=="00")$img="http://dealgiadung.com/deal_css/images/y.png";
            
            $img = file_get_contents($img); 
            header('content-type: image/gif'); 
            echo $img; 
            
            
        }
        function AddMail(){
            $this->load->model('deal/customer_model','customer_model');
            $mail=$_POST["Mail"];
            if(@preg_match("/^[0-9a-zA-Z]\w+(\.\w+)*\@\w+(\.[0-9a-zA-Z]+)*\.[a-zA-Z]{2,4}$/", $_POST["Mail"]) === 0){
                $code=-1;
                $msg="Email không hợp lệ";
            }else{
                $params=array("Email"=>$mail);
                $cus=$this->customer_model->getMail($mail);
                if(isset($cus[0])){
                    $code=-1;
                    $msg="Email của bạn đã nằm trong danh sách nhận thông tin deal hàng ngày.";
                }else{
                    if($this->customer_model->insertMail($params)){
                        $code=1;
                        $msg="Đã Thêm Email của bạn vào mục nhận thông tin deal hàng ngày.";
                    }else{
                        $code=-1;
                        $msg="Hệ thống đang bận. Vui lòng thử lại sau";
                    }
                }
            }
            $result=array("code"=>$code,"msg"=>$msg);
            echo json_encode($result);
        }
        function Init(){
            $Data=null;
            $this->load->model('APanel/region_model');
            $this->region_model=new region_model();
            
            $this->load->model('APanel/setting_model');
            $this->setting_model=new setting_model();
            $tmp=$this->setting_model->gets();
            if(count($tmp)>0){
                foreach($tmp as $s){
                    $Data["aSettings"][$s->Key]=$s->Value;
                }
                $_SESSION["aSettings"]=$Data["aSettings"];
            }
            
            $this->load->model('APanel/type_model');
            $this->type_model=new type_model();
            $Regions=$this->region_model->getCitys();
            if(count($Regions)>0){
                foreach ($Regions as $r){
                    $tmp=null;
                    $tmp["name"]=$r->TenTinhThanh;
                    $tmp["id"]=$r->ID;
                    $Data["Regions"][]=$tmp;
                }
                $_SESSION["regions"]=$Data["Regions"];
            }
            
            $oFoots=$this->type_model->getfoots();
            if(count($oFoots)>0){
                foreach ($oFoots as $f){

                    $tmp=null;
                    $tmp["title"]=$f["Name"];
                    $tmp["link"]=$f["Value"];
                    $aFoots[$f["Type"]][]=$tmp;
                }
                $_SESSION["aFoots"]=$aFoots;
            }
        }
        function htmlDistrict($City=""){
            $this->load->model('APanel/region_model');
            $this->region_model=new region_model();
            $this->load->model('APanel/type_model');
            $this->type_model=new type_model();
            $Districts=$this->region_model->getDistricts($City);
            echo '
                <select id="cbxQuan" onchange="DistricChange()" class="pl4 pb4 pt4 pr4" style="width: 160px;margin-right: 0px" >
                    <option value="">[ --- Quận/Huyện --- ]</option>';
            if(count($Districts)>0)
                foreach($Districts as $d){
                echo "<option value='$d->ID'>$d->TenQuanHuyen</option>";
                }
            echo "</select>";
        }
        function htmlWard($District=""){
            $this->load->model('APanel/region_model');
            $this->region_model=new region_model();
            $this->load->model('APanel/type_model');
            $this->type_model=new type_model();
            $Districts=$this->region_model->getWard($District);
            echo '
                <select id="cbxPhuong" class="pl4 pb4 pt4 pr4" style="width: 160px;margin-right: 0px" >
                    <option value="">[ --- Phường/Xã --- ]</option>';
            if(count($Districts)>0)
                foreach($Districts as $d){
                echo "<option value='$d->ID'>$d->TenPhuongXa</option>";
                }
            echo "</select>";
        }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */